/*    */ package cc.s2m.web.s2mBlog.controller;
/*    */ 
/*    */ import cc.s2m.web.s2mBlog.controller.base.BaseController;
/*    */ import cc.s2m.web.s2mBlog.util.StaticProp;
/*    */ import java.util.Arrays;
/*    */ import java.util.HashMap;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.UUID;
/*    */ import main.java.com.UpYun;
/*    */ import org.apache.commons.codec.digest.DigestUtils;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.RequestParam;
/*    */ import org.springframework.web.bind.annotation.ResponseBody;
/*    */ import org.springframework.web.multipart.MultipartFile;
/*    */ 
/*    */ @Controller
/*    */ public class UmeditorUpload extends BaseController
/*    */ {
/* 22 */   private Map<String, String> resultJson = new HashMap();
/*    */ 
/*    */   @RequestMapping(value={"/umUpload"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   @ResponseBody
/*    */   public Map<String, String> helloWorld(@RequestParam MultipartFile upfile)
/*    */   {
/* 30 */     if ((upfile == null) || (upfile.getSize() < 1L)) {
/* 31 */       this.resultJson.put("state", "未包含文件上传域");
/* 32 */       return this.resultJson;
/*    */     }
/* 34 */     String fileName = upfile.getOriginalFilename();
/* 35 */     Iterator type = Arrays.asList(StaticProp.allowFiles).iterator();
/* 36 */     boolean allowFilesFlag = false;
/* 37 */     while (type.hasNext()) {
/* 38 */       String ext = (String)type.next();
/* 39 */       if (fileName.toLowerCase().endsWith(ext)) {
/* 40 */         allowFilesFlag = true;
/*    */       }
/*    */     }
/* 43 */     if (!allowFilesFlag) {
/* 44 */       this.resultJson.put("state", "不允许的文件格式");
/* 45 */       return this.resultJson;
/*    */     }
/* 47 */     String url = StaticProp.upYunPath + DigestUtils.md5Hex(UUID.randomUUID().toString());
/* 48 */     url = url + fileName.substring(fileName.lastIndexOf("."));
/*    */     try {
/* 50 */       boolean a = StaticProp.upyun.writeFile(url, upfile.getBytes(), true);
/* 51 */       if (!a)
/* 52 */         this.resultJson.put("state", "上传到upyun失败");
/*    */     }
/*    */     catch (Exception e) {
/* 55 */       e.printStackTrace();
/* 56 */       this.resultJson.put("state", e.getMessage());
/* 57 */       return this.resultJson;
/*    */     }
/* 59 */     this.resultJson.put("state", "SUCCESS");
/* 60 */     this.resultJson.put("size", String.valueOf(upfile.getSize()));
/* 61 */     this.resultJson.put("originalName", fileName);
/* 62 */     this.resultJson.put("name", url);
/* 63 */     this.resultJson.put("url", "http://img.s2m.cc/" + url);
/* 64 */     this.resultJson.put("type", fileName.substring(fileName.lastIndexOf(".")));
/* 65 */     return this.resultJson;
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.controller.UmeditorUpload
 * JD-Core Version:    0.6.1
 */